<template>
  <!--积分列表  唐美莉 -->
  <section>
    <table border="0" width="100%" style="border-spacing: 0;border-collapse: collapse;">
      <tr>
        <td>
          <el-form :inline="true">
            <el-form-item>
              <el-input v-model="form.nameOrMobile" placeholder="患者姓名/手机号"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" circle icon="el-icon-search" @click="getData(-1)"></el-button>
            </el-form-item>
          </el-form>
        </td>
      </tr>
    </table>
    <table class="table-box">
      <thead>
        <tr>
          <th>姓名</th>
          <th>手机号</th>
          <th>积分</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="(item,index) in tableList" :key="index">
          <td>{{item.name}}</td>
          <td>{{item.mobil}}</td>
          <td>{{item.patientScore}}</td>
          <td >
            <el-link v-if="qxBtns.update" :underline="false" @click="onJoin(item)"   type="primary">更改积分</el-link>&nbsp;
            <el-link v-if="qxBtns.reset"  :underline="false" @click="reset(item)"    type="danger" >清零</el-link>&nbsp;
            <el-link v-if="qxBtns.record" :underline="false" @click="getOrder(item)" type="primary" >查看记录</el-link>
          </td>
        </tr>
      </tbody>
    </table>
    <div v-if="tableList.length == 0" style="color:#999;padding:10px 0;text-align:center;">
      <i class="iconfont iconwushuju" style="font-size:40px;"></i>
      <div>暂无数据</div>
    </div>
    <br />
    <pager v-model="pager" @change-pagenum="getData"></pager>
    <set v-model="dialogJoin" :curItem="curItem" @success="getData"></set>
    <record v-model="dialogEdit" v-if="dialogEdit" :curItem="curItem" @success="getData"></record>
  </section>
</template>
<script>
import Excel from "@/_js/excel.js";
export default {
  name: "integralList",
  data() {
    return {
      dialogJoin: false,
      dialogEdit: false,
      curItem: null,
      pager: { pageSize: 10, pageNum: 1, total: 0 },
      tableList: [],
      form: {
        hpId: "",
        nameOrMobile: "", 
        type:10,
        status:''
      },
      pickerOptions: {
        disabledDate: (time) => {
          return time.getTime() > Date.now()
        }
      }, 
      typeList: [],
      qxBtns: {},
      dataList: [],
      distype: "2",
      setType: "1"
    };
  },
  created() {
    let th = this;
    th.form.hpId = th.adminUser.hpId;
    th.getQX();
    th.getData();
  },
  methods: {
    onJoin(obj) {
      this.dialogJoin = true;
      this.curItem = obj;
    },
    getOrder(obj){
      this.dialogEdit = true;
      this.curItem = obj;
    },
    reset(obj, index) {
      let th = this;
      th.$confirm(`确定清零吗?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true
      })
        .then(() => {
          let j = { patientId: obj.patientId,num:0,type:3,desc:'' };
          th.showLoading();
          th.$api.updateRecord(j).then(res => {
            if (res.executed) {
              th.$message.success("清零成功");
              th.getData();
            } else {
              th.$message.error(res.message);
            }
            th.showLoading(false);
          });
        })
        .catch(() => {});
    },
    getData(type) {
      let th = this;
      if (type == -1) {
        th.pager.pageNum = 1;
        th.pager.total = 0;
      }
      let j = {};
      Object.assign(j, th.pager);
      Object.assign(j, th.form);
      th.showLoading();
      th.$api.getThePatientLibraryList(j).then(res => {
        if (res.executed) {
          if (res.dataBody != undefined) {
            th.tableList = res.dataBody.list;
            th.pager.total = res.dataBody.total;
          } else {
            th.tableList = [];
            th.pager.total = 0;
          }
          th.showLoading(false);
        }
      });
    }
  },
  components: {
    set: () => import("./_com/update.vue"),
    record:() => import("./_com/record.vue")
  }
};
</script>
